package com.example.transit.contentprovider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.transit.bean.StationInfo;

public class DbStationInfo {

	private static final String TAG = "DbStationInfo";
	private ContentResolver mContentResolver;
	private DbHelper dh;

	public DbStationInfo(ContentResolver mContentResolver,Context content){
		this.mContentResolver = mContentResolver;

		this.dh=new DbHelper(content);
	}


	public void InsertAllStaInfo(StationInfo info){

		ContentValues cv = new ContentValues();
		String[] projection ={DbHelper.COLUME_ALLSTA_ID};
		int id = 0;
		Cursor cursor = mContentResolver.query(DbContentProvider.CONTENT_URI_ALLSTATIONINFO, projection, null, null, null);
		if(cursor.moveToFirst()){
			id=cursor.getInt(0);
		}
		id++;

		cv.put(DbHelper.COLUME_ALLSTA_ID, id);
		cv.put(DbHelper.COLUME_ALLSTA_LINE, info.getLineNum());
		cv.put(DbHelper.COLUME_ALLSTA_STA_NAME, info.getStationName());
		cv.put(DbHelper.COLUME_ALLSTA_STA_ORDER, info.getLineStationOrder());
		cv.put(DbHelper.COLUME_ALLSTA_GPS_X, info.getLinelongitude());
		cv.put(DbHelper.COLUME_ALLSTA_GPS_Y, info.getLinelatitude());
		cv.put(DbHelper.COLUME_ALLSTA_DIRECT, info.getIsupline());
		mContentResolver.insert(DbContentProvider.CONTENT_URI_ALLSTATIONINFO,cv);
		cursor.close();
	}


	public void deleteAllStationInfo(){
		mContentResolver.delete(DbContentProvider.CONTENT_URI_ALLSTATIONINFO, null, null);
	}
}